<template>
  <div style="margin-top: 11px;">
    <div class="Chnav">
      用户名： {{adminName}}
    </div>
    <div class="Chnav">
      旧密码：
      <div>      <input type="password" class="Chinput" v-model="data.oldPassword">
      <i class="notice" v-if="data.oldPassword==''">不修改密码请留空。</i>
      </div>
    </div>
      <div class="Chnav">
      新密码：
      <div >      <input type="password" class="Chinput" v-model="data.newPassword">
      <i class="notice" v-if="data.newPassword===''">不修改密码请留空。</i>
      <i class="notice" v-else-if="data.newPassword===data.oldPassword">不能使用原密码</i>
      <!-- <i class="notice1" v-else></i> -->
      </div>

    </div>
    <div class="Chnav Chnav-1">
      重复新密码：
      <div>      <input type="password" v-model="data.repetition">
      <i class="notice" v-if="data.repetition==''">不修改密码请留空。</i>
      <i class="notice" v-else-if="data.repetition!=data.newPassword">请确定密码</i>
      <i class="notice1" v-else></i>
      </div>
   </div>
   <button v-if="data.repetition==data.newPassword&&data.newPassword!=data.oldPassword" @click="Submit()">提交</button>
  </div>
</template>

<script>
    export default {
      name:'ChPass',
      data(){
        return{
          data:{
            oldPassword:'',//旧密码
            newPassword:'',//新密码
            repetition:'',//重复
          },
          adminName:'',
        }
      },
      methods:{
        Submit(){
          var _this=this
          if(this.$cookies.get('token')&&this.$cookies.get('adminName')){
            this.$axios({
                      method: "POST",
                      url: '/api/admin/password/reset',
                      data: {
                          adminName:_this.$cookies.get('adminName'),
                          token:_this.$cookies.get('token'),
                          oldPassword:_this.data.oldPassword,
                          newPassword:_this.data.newPassword
                  },
                      headers: {
                          'Content-Type': 'application/json'
                      }
            })
           .then(function (response) {
             if(response.data.code==0){
               //console.log(11111)
              // _this.$router.push({ name:'login'});
                // _this.$cookies.set('adminName', _this.name)
                // _this.$cookies.set('token', response.data.data.token)
                // _this.$router.push({ name:'Head'  });
             }
             console.log(response);
           })
           .catch(function (error) {
             console.log(error);
           });
          }else{
            this.$confirm('登录信息过期, 请重新登录', '提示', {
           confirmButtonText: '确定',
           type: 'warning'
         }).then(() => {
          this.$router.push({ name:'login'  });
         }).catch(() => {
          this.$router.push({ name:'login'  });
         });
          }

        }
      },
      mounted(){
          this.adminName=this.$cookies.get('adminName')
      }
    }
</script>

<style scoped>
  .notice{
    background-image: url(../../assets/notice.png);
    background-repeat: no-repeat;
    padding-left: 16px;
  }
  .notice1{
    background-image: url(../../assets/correct.png);
    background-repeat: no-repeat;
    padding-left: 16px;
  }
.Chnav{
  display: flex;
  border-top: 1px solid #999999;
  height: 70px;
  line-height: 70px;
  width: 95%;
  margin: auto;
}
.Chnav-1{
 border-bottom: 1px solid #999999;
}
button{
  margin-left: 2.5%;
  margin-top: 15px;
}
.Chinput{
  margin-left: 33px;
}
</style>
